home *** CD-ROM | disk | FTP | other *** search
- #!/usr/sbin/perl
-
- $K=1024; #1-K
- $Meg=$K*$K; #1-Meg
- $XCONFIRM='/usr/bin/X11/xconfirm';
-
- $NEW_DISK_SPACE_REQUIRED=90*$K; #size in Kilobytes needed
-
- #return codes
- $CREATE_NEW_HD=0; # 0 - ok create new hard disk
- $UPGRADE_FAILED=1; # 1 - $MV or $CP of old HD failed - reason unknown
- $BOOT_OFF_NEW=2; # 2 - the new is ready to be booted off of
- $CONTINUE=3; # 3 - Continue back in SWIN
- $E_NOSPACE=4; # 4 - we are exiting for not enough space -
- # SWIN will give user a 2nd chance here
-
- $MV="/sbin/mv";
- $CP="/sbin/cp";
-
-
- #$name=getpwuid($<);
- #$home=(getpwuid($<))[7];
- $name=$ENV{"USER"};
- $home=$ENV{"HOME"};
-
- $OLD_DISK="$home/WIN31-$name.hdf";
- $NEW_DISK="$home/WIN311-$name.hdf";
-
- Retry:
-
- #sanity check
- if (-e $NEW_DISK) { exit $BOOT_OFF_NEW; }
-
-
- #get free disk space on home device
- $_=`/usr/sbin/df -k $home|/bin/tail -1`;
- ($free_space)=/.{27}\s*\S+\s+\d+\s+\d+\s+(\d+).*/;
-
-
- #find size of old hard disk in K
-
- $old_size=((($old_exists=-R $OLD_DISK)?-s $OLD_DISK:0)+$K-1)/$K;
-
- if (!$old_exists) {
- #nothing to copy -- do we have enough space to create a new HD?
- if ($NEW_DISK_SPACE_REQUIRED < $free_space) { exit $CREATE_NEW_HD;}
- else {
- exit $E_NOSPACE;
- }
- }
-
- #old exists, enough space to copy the old?
-
- if ($old_size<$free_space) {
- if (system("$CP -p $OLD_DISK $NEW_DISK")) {
- system("rm $NEW_DISK"); #remove any turds
- if ($NEW_DISK_SPACE_REQUIRED < $free_space) { exit $CREATE_NEW_HD; }
- else {
- exit $E_NOSPACE;
- }
- }
- #getting here means $CP succeeded...
- exit $BOOT_OFF_NEW;
- }
-
- #Ok, we got here...what to do.
- #first -- we *could* rename the old
- #second, we *might* be able to create a new HD
- #third, we offer to exit for them!
- if ($NEW_DISK_SPACE_REQUIRED < $free_space) {
- #3 choice popup!
- $prog="$XCONFIRM".' -c -b "Continue" -b "Create" -B "Upgrade" -b "Retry" '.
- '-header "Insufficient Space" '.
- '-t "There is not enough space to make" '.
- '-t "a backup of your current hard disk." '.
- '-t "You can IRREVERSIBLY <Upgrade> your" '.
- '-t "current hard disk, <Create> a new hard" '.
- '-t "disk, or <Continue>." '.
- '-icon question -geometry "360x190"';
- } else {
- #2 choice popup
- $prog="$XCONFIRM".' -c -b "Continue" -B " Upgrade" -b "Retry" '.
- '-header "Insufficient Space" '.
- '-t "There is not enough space to make" '.
- '-t "a backup of your current hard disk" '.
- '-t "or to create a new hard disk." '.
- '-t "You can IRREVERSIBLY <Upgrade> your" '.
- '-t "current hard disk, or <Continue> with" '.
- '-t "more options." '.
- '-icon question -geometry "360x190"';
- }
-
- $_=`$prog`;
-
- if (/Upgrade/) {
- if (system("$MV $OLD_DISK $NEW_DISK")) {
- # yuck this failed. Not much to do
- $prog="$XCONFIRM".' -c -B "Continue" -b "Retry" '.
- '-header "Cannot Rename"" '.
- '-t "Your old hard disk could not be " '.
- '-t "renamed. This might be a permission" '.
- '-t "problem. " '.
- '-icon question -geometry "360x190"';
- $_=`$prog`;
-
- if (/Retry/) {
- goto Retry;
- }
- exit $CONTINUE;
- }
- exit $BOOT_OFF_NEW;
- } elsif (/Continue/) {
- exit $CONTINUE;
- } elsif (/Retry/) {
- goto Retry;
- } else {
- exit $CREATE_NEW_HD;
- }
-